<?php
if(!defined('DCS_ROOT')) {exit('Access Denied');}

class main {

	function __construct() {
		$this->defaultAction();
		exit();
	}
	function defaultAction(){		
		$url = getUrl();
		$refer = getReferer();
		if(isPost()) {
			$email =  addslashes(trim($_POST['email']));
			$password =  addslashes(trim($_POST['password']));
			$refer =  addslashes(trim($_POST['refer']));
			if(!empty($password)){
				require_once(APP_PATH."model/accounts.php" );
				$DB  = getDB();
				$user = new accountsModel($DB);
				$login	= $user->login($email,$password);
				if ($login){					
					if (!empty($refer)){
						echo '<script language="javascript">location.href="'.$refer.'";</script>';
					}else{
						echo '<script language="javascript">location.href="/";</script>';
					}
				}else{
					$message = '<DIV class=message>&nbsp;邮箱或密码不正确。</DIV>';					
				}
			}else{
				$message = '<DIV class=message>&nbsp;请输入邮箱或密码。</DIV>';
			}

			$tpl = new Template("accounts/login.htm");
			$tpl->assign("message",$message);
			$tpl->assign(assignUser());
			$tpl->output();
		}else{
			$tpl = new Template("accounts/login.htm");
			$var['refer'] = $refer;
			$tpl->assign($var);
			$tpl->assign(assignUser());
			$tpl->output();
			
			

	   
	   
		}
	}

}

?>
